<script lang="ts" setup>
import type { NotifyItem } from "./type"
import { Bell } from "@element-plus/icons-vue"
import { notifyData } from "./data"
import List from "./List.vue"
import { inject } from 'vue'
const CL: any = inject("$CL");
import { useI18n } from 'vue-i18n';
const { locale, t } = useI18n();//登录国籍
type TabName = "异常订单" | "强制下架的商品" | "强制下架的广告"

interface DataItem {
  name: String
  type: "primary" | "success" | "warning" | "danger" | "info"
  list: NotifyItem[]
}

/** 角标当前值 */
const badgeValue = computed(() => data.value.reduce((sum, item) => sum + item.list.length, 0))

/** 角标最大值 */
const badgeMax = 99

/** 面板宽度 */
const popoverWidth = 420

/** 当前 Tab */
const activeName = ref<String>(t('notice.异常订单'))

/** 所有数据 */
const data = ref<DataItem[]>([
  // 通知数据
  {
    name: t('notice.异常订单'),
    type: "primary",
    list: notifyData
  },
  // 消息数据
  {
    name: t('notice.强制下架的商品'),
    type: "danger",
    list: notifyData
  },
  // 待办数据
  {
    name: t('notice.强制下架的广告'),
    type: "warning",
    list: notifyData
  }
])

function handleHistory() {
  ElMessage.success(`跳转到${activeName.value}历史页面`)
}
</script>

<template>
  <div class="notify">
    <el-popover placement="bottom" :width="popoverWidth" trigger="click" popper-class="notify-self">
      <template #reference>
        <el-badge :value="badgeValue" :max="badgeMax" :hidden="badgeValue === 0">
          <el-tooltip effect="dark" :content="t('notice.消息通知')" placement="bottom">
            <el-icon :size="20">
              <Bell />
            </el-icon>
          </el-tooltip>
        </el-badge>
      </template>
      <template #default>
        <el-tabs v-model="activeName" class="demo-tabs" stretch>
          <el-tab-pane v-for="(item, index) in data" :key="index" :name="item.name">
            <template #label>
              {{ item.name }}
              <el-badge :value="item.list.length" :max="badgeMax" :type="item.type" />
            </template>
            <el-scrollbar class="liying-notify-info">
              <List :data="item.list" :type="activeName"/>
            </el-scrollbar>
          </el-tab-pane>
        </el-tabs>

      </template>
    </el-popover>
  </div>
</template>

<style lang="scss" scoped>
.notify-history {
  text-align: center;
  padding-top: 12px;
  border-top: 1px solid var(--el-border-color);
}
</style>


<style>
  .notify-self {
    border-radius: 20px !important;
  }
</style>
